<template>
  <div class="login-block">
    <div class="center-block">
      <div class="login">
        <div class="login-top">
          <div class="cn">
            <span>{{ $t("lang.Title") }}</span>
          </div>
          <img class="logo" src="@/assets/photo/logo.png" />
        </div>
        <div class="message">
          <el-form :rules="rules" ref="ruleForm" :model="ruleForm">
            <el-form-item prop="account">
              <div>{{ $t("lang.account") }}:</div>
              <el-input
                type="text"
                v-model="ruleForm.account"
                autocomplete="off"
              >
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <div>{{ $t("lang.password") }}:</div>
              <el-input
                type="password"
                v-model="ruleForm.password"
                suffix-icon="el-icon-view"
                autocomplete="off"
              ></el-input>
              <a href="#">{{ $t("lang.forgetPassword") }}</a>
            </el-form-item>
            <el-form-item>
              <el-button style="width: 100%" type="primary" @click="submitForm">
                {{ $t("lang.login") }}
              </el-button>
            </el-form-item>
            <el-form-item>
              <el-button style="width: 100%; color: #409eff" plain>
                {{ $t("lang.prompt") }}
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
    <div class="bottom-block">
      <div class="first-block">
        <img src="@/assets/photo/seeed.png" />
      </div>
      <div class="second-block">
        <span>©{{ $t("lang.copyright") }}</span>
      </div>
      <div class="third-block">
        <span> {{ $t("lang.privacy") }}</span>
      </div>
      <div class="fourth-block">
        <img src="@/assets/photo/mcafee.png" />
      </div>
      <div class="fifth-block">
        <el-select
          placeholder="$('lang.lang')"
          v-model="lang"
          @change="changeLang"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      select: "",
      ruleForm: {
        account: "",
        password: "",
      },
      rules: {
        account: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [
          { required: true, message: "请输入用户密码", trigger: "blur" },
        ],
      },
      options: [
        {
          value: "zh",
          label: this.$t("lang.cs"),
        },
        {
          value: "en",
          label: this.$t("lang.is"),
        },
      ],
      lang: "",
    };
  },
  methods: {
    // 登录
    submitForm() {
      // 1.验证输入的用户名和密码是否正确
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          // 验证成功
          // 调用vuex中 user子树里面的登录的action动作
          this.$store.dispatch("LoginAction", this.ruleForm);
        } else {
          console.log("验证没通过");
        }
      });
    },
    // 切换语言集
    changeLang() {
      this.$store.commit("SET_LANG", this.lang);
      // 整个页面刷新
      this.$router.go(0);
    },
  },
  created() {
    this.lang = this.$store.getters.locale;
  },
};
</script>

<style scoped lang="scss">
.login-block {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #ebeef2;
}

.center-block {
  flex: 1;
  overflow: auto;
  position: relative;
  .login {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 350px;
    height: 480px;
    margin: auto;
    background-color: #fff;
    .login-top {
      width: 100%;
      height: 100px;
      position: relative;
    }
    .message {
      padding: 0 20px;
    }
  }
}

.bottom-block {
  width: 100%;
  height: 55px;
  background-color: #fff;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  div {
    margin-right: 40px;
    flex-wrap: wrap;
  }
  img {
    width: 100%;
  }
  .first-block {
    width: 120px;
  }
  .second-block {
    width: 270px;
  }
  .third-block {
    margin-bottom: 10px;
  }
  .fourth-block {
    width: 80px;
  }
}

.cn {
  position: absolute;
  top: 0;
  right: 0;
  height: 0;
  width: 0;
  border-style: solid;
  border-width: 0px 50px 50px 0;
  border-color: transparent blue transparent transparent;
  span {
    position: absolute;
    top: 2px;
    right: -45px;
    font-size: 16px;
    color: #fff;
    font-weight: bold;
  }
}

.logo {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 140px;
}

span,
a {
  font-size: 12px;
  color: #535151;
}

/deep/ .el-form-item__content {
  line-height: initial;
}
</style>
